﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Portalz.Engine
{
    public class Formulas
    {
        public static Int32 level(Character character, Class aClass)
        {
            return Data.RandNum(character.Level - 1 > Data.MIN_LEVEL ? character.Level - 1 : Data.MIN_LEVEL, character.Level + 1 < Data.MAX_LEVEL ? character.Level + 1 : Data.MIN_LEVEL);
        }

        public static Int32 attack(Character character, Class aClass)
        {
            return aClass.AttackMod + (character.Level * 3);
        }

        public static Int32 accuracy(Character character, Class aClass)
        {
            return aClass.AccuracyMod;
        }

        public static Int32 defense(Character character, Class aClass)
        {
            return aClass.DefenseMod + (character.Level * 3);
        }

        public static Int32 money(Character character, Class aClass)
        {
            return (character.Level * (10 + Data.RandNum(1, 5) * Data.RandNum(3, 5)));
        }

        public static Int32 experience(Character character)
        {
            return (character.Level * (10 + Data.RandNum(1, 5))) * Data.RandNum(3, 5);
        }

        public static Int32 speed(Character character, Class aClass)
        {
            return aClass.SpeedMod;
        }

        public static Int32 damage(Int32 attack, Int32 critChance, Int32 hitChance, Int32 defense, Int32 speed)
        {
            if (!rngProc(hitChance)) { return -1; }
            Double dmg;
            dmg = attack * (speed / 200);
            Double reduction = (defense / defense + 40 + (8.5 * (defense / 2)));
            dmg *= reduction > 0.75 ? 0.75 : reduction;
            if (rngProc(critChance)) { dmg *= 2; }
            return Convert.ToInt32(dmg);
        }

        public static Boolean rngProc(Int32 chance)
        {
            Int32 roll = Data.RandNum(1, 100);
            if (roll >= 1 || roll <= chance) { return true; }
            else { return false; }
        }

    }
}
